/**
 * 基本数据存储
 *
 */
import { getUserInfo } from 'api/mock'

const state = {
  input1: '',
  userInfo: {},
  array1: []
}
const SET_USERINFO = 'setUserInfo'

const actions = {
  setInput({ state, commit, dispatch }) {
    console.log(commit)
  },
  updateUserInfo({ commit }) {
    commit(SET_USERINFO)
    return new Promise(resolve => {
      getUserInfo().then(res => {
        resolve(res)
      })
    })
  },
  async asyncGetUserInfo({ commit }) {
    const res = await getUserInfo()
    commit('setUserInfo', res)
    return res
  }
}

const mutations = {
  // 设置userInfo
  [SET_USERINFO](state, userInfo) {
    // 变更状态
    state.userInfo = userInfo
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
